#ifndef AnimMontage_H
#define AnimMontage_H

#include <QObject>
#include <QMap>
#include <QPointer>
#include <QtQmlIntegration>

#include "PoseNode.h"

//动画蒙太奇，用于将多个独立的动画进行混合后输出给指定的骨骼

class AnimMontagePrivate;

class AnimMontage:public QObject
{
    Q_OBJECT
    QML_ELEMENT
    Q_PROPERTY(QObject *target READ getTarget WRITE setTarget NOTIFY targetChanged FINAL)
    Q_PROPERTY(PoseNode *source READ getSource WRITE setSource NOTIFY sourceChanged FINAL)
    Q_PROPERTY(bool running READ getRunning WRITE setRunning NOTIFY runningChanged FINAL)
public:
    AnimMontage();
    ~AnimMontage();


    QObject *getTarget() const;
    void setTarget(QObject *newTarget);

    PoseNode *getSource() const;
    void setSource(PoseNode *newSource);

    bool getRunning() const;
    void setRunning(bool newRunning);

signals:
    void targetChanged();
    void sourceChanged();

    void runningChanged();

private:
    void update();
    void onTargetUpdate();
    void postFrame();
    void applyEntrys(const Pose& entrys);
private:
    AnimMontagePrivate* _P;

    QObject* target = nullptr;//动画的输出目标
    PoseNode* source = nullptr;//动画源
    bool running = false;
    bool active = false;
    QMap<QString,QPointer<QObject>> idMap;
};

#endif
